#include "qs_settings.h"

static __no_init qs_settings_job_t m_settings_job;
static __no_init qs_settings_job_t mem_settings_job;
static  qs_settings_sens_t m_settings_sens;

qs_settings_job_t* qs_settings_job_get(void)
{
    return &m_settings_job;
}

qs_settings_job_t* qs_mem_settings_job_get(void)
{
    return &mem_settings_job;
}

qs_settings_sens_t * qs_settings_sens_get(void)
{
    return &m_settings_sens;
}
static bool is_data_invalid(void)
{
    if(m_settings_job.work_mode > 4) {
        return true;
    } 
    if(m_settings_job.auto_mode > 6) {
        return true;
    } 
    if(m_settings_job.fan_level > 5) {
        return true;
    }
    if(m_settings_job.heat_level > 18) {
        return true;
    }
    if(m_settings_job.timer > 28800) {
        return true;
    }
    if(m_settings_job.mode_timeout > 120) {
        return true;
    }
    return false;
}


void qs_settings_init(bool reset)
{
    if(reset || is_data_invalid()) {
        memset(&m_settings_job, 0, sizeof(m_settings_job));
        memset(&mem_settings_job, 0, sizeof(mem_settings_job));
    }
    memset(&m_settings_sens, 0, sizeof(m_settings_sens));
    m_settings_sens.temp0 = INT8_MIN;
    m_settings_sens.temp1 = INT8_MIN;
    m_settings_sens.humid0 = UINT8_MAX;
    m_settings_sens.humid1 = UINT8_MAX;
    
}

